/*TCSS 360 ConferenceGuru
 * 
 * Lawrence
 */
package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/*
 * A class that represents a Reviewer role in a conference.
 */
public class Reviewer implements Serializable
{
	private static final long serialVersionUID = 7164769754810499849L;
	//The list of the Reviewers assigned papers
	private ArrayList<ConferencePaper> my_assigned_manuscripts = new ArrayList<ConferencePaper>();
	//The Reviewers user name
	private String my_user;
	
	/*
	 * Constructs the Reviewer by setting the user name.
	 */
	public Reviewer(String the_user)
	{
		my_user = the_user;
	}
	
	/*
	 * Gets the user name and returns it.
	 */
	public String getUser()
	{
		return my_user;
	}
	
	/*
	 * Gets all of the Reviewers assigned manuscripts and returns them.
	 */
	public ArrayList<ConferencePaper> getManuscripts()
	{
		return my_assigned_manuscripts;
	}
	
	/*
	 * Returns false if this reviewer has already been assigned a paper
	 * to review more than 4 times in this conference, otherwise adds the paper
	 * to his papers to review.
	 */
	public boolean setManuscript(ConferencePaper manuscript)
	{
		if(my_assigned_manuscripts.size() < 4)
		{
			my_assigned_manuscripts.add(manuscript);
			
			return true;
		}		
		
		return false;		
	}
	
	/*
	 * Takes the information entered by the gui and makes a Review object and then 
	 * adds that Review object to the ConferencePaper.
	 */
	public void SubmitReview(Review the_review, String paper_title)
	{
		
		for(ConferencePaper manuscript: my_assigned_manuscripts)
		{
			if(manuscript.getTitle() == paper_title)
			{
				manuscript.setReview(the_review);
			}
		}	
	}
	
	/*
	 * Gets a Review that this Reviewer already submitted to a conference paper.
	 */
	public Review getReview(String paper_title)
	{
		List<Review> paper_reviews = new ArrayList<Review>();
		for(ConferencePaper manuscript: my_assigned_manuscripts)
		{
			if(manuscript.getTitle() == paper_title)
			{
				paper_reviews = manuscript.getReviews();
			}
		}	
		
		for(Review review: paper_reviews)
		{
			if(review.getReviewer() == my_user)
			{
				return review;
			}
		}
		return null;
	}
}
